package com.ruoyi.system.service.impl;

import com.ruoyi.system.entity.AgencyTask;
import com.ruoyi.system.mapper.AgencyTaskMapper;
import com.ruoyi.system.service.AgencyTaskService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 待办任务表(AgencyTask)表服务实现类
 *
 * @author makejava
 * @since 2022-12-05 21:38:05
 */
@Service("agencyTaskService")
public class AgencyTaskServiceImpl implements AgencyTaskService {
    @Resource
    private AgencyTaskMapper agencyTaskDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public AgencyTask queryById(Integer id) {
        return this.agencyTaskDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param agencyTask 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<AgencyTask> queryByPage(AgencyTask agencyTask, PageRequest pageRequest) {
        long total = this.agencyTaskDao.count(agencyTask);
        return new PageImpl<>(this.agencyTaskDao.queryAllByLimit(agencyTask, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param agencyTask 实例对象
     * @return 实例对象
     */
    @Override
    public AgencyTask insert(AgencyTask agencyTask) {
        this.agencyTaskDao.insert(agencyTask);
        return agencyTask;
    }

    /**
     * 修改数据
     *
     * @param agencyTask 实例对象
     * @return 实例对象
     */
    @Override
    public AgencyTask update(AgencyTask agencyTask) {
        this.agencyTaskDao.update(agencyTask);
        return this.queryById(agencyTask.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.agencyTaskDao.deleteById(id) > 0;
    }
}
